#include <vector>
#include <set>
using namespace std;

class Solution {
public:
    int maxLength(vector<int>& arr) {
        int ret = 0, tmp = 0;
        set<int> set1;
        for (int i = 0, j = 0; j < arr.size(); j++)
        {
            if (set1.count(arr[j]))
            {
                while (set1.count(arr[j]))
                {
                    set1.erase(arr[i++]);
                }
                set1.insert(arr[j]);
            }
            else
            {
                set1.insert(arr[j]);
                ret = max(ret, j - i + 1);
            }
        }
        return ret;
    }
};
